package com.zzyl.nursing.controller.member;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.BindingElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyMemberElderPageVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author zbr
 * @date 2025-03-03
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 修改老人家属
     */
    @ApiOperation("修改老人家属")
    @PreAuthorize("@ss.hasPermi('nursing:member:edit')")
    @Log(title = "老人家属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("老人家属信息") @RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.updateFamilyMember(familyMember));
    }

    /**
     * 小程序登录
     *
     * @param userLoginRequestDto C端用户登录
     * @return 登录结果
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return R.ok(loginVo);
    }

    /**
     * 绑定老人
     * @param bindingElderDto 老人信息
     * @return 绑定结果
     */
    @PostMapping("/add")
    @ApiOperation("绑定老人")
    public AjaxResult add(@RequestBody BindingElderDto bindingElderDto) {
        familyMemberService.add(bindingElderDto);
        return AjaxResult.success();
    }

    /**
     * 获取用户绑定家人列表
     *
     * @return
     */
    @GetMapping("/my")
    @ApiOperation("获取用户绑定家人列表")
    public R<List<FamilyMemberElderVo>> my() {
        return R.ok(familyMemberService.getMyFamilyMemberElder());
    }

    /**
     * 分页查询用户绑定老人
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    public R<List<FamilyMemberElderPageVo>> listByPage(Integer pageNum, Integer pageSize) {
        return R.ok(familyMemberService.getMyFamilyMemberElderPage(pageNum, pageSize));
    }

}
